var form;
var upload;

var houseFloorPlanName;

$(document).ready(function () {
    layui.use(['form', 'upload'], function () {
        form = layui.form;
        upload = layui.upload;

        form.render();
        initUpload();
    });
});

function initUpload() {

    upload.render({
        elem: '#floor-plan-btn-choose'
        , auto: false
        , accept: 'image'
        , exts: 'jpg|png|gif'
        , headers: {'Authorization': token}
        , method: 'POST'
        , url: apiHostUrl + '/admin/floorplan/addFloorPlan'
        , bindAction: '#floor-plan-btn-submit'
        , field: "houseFloorPlanFile"
        , data: {
            houseFloorPlanName: function () {
                return $("#floorPlanName").val();
            }
        }
        , choose: function (obj) {
            // 预读本地文件
            obj.preview(function (index, file, result) {
                $('#img-header').attr('src', result);
            });
        }
        , done: function (result, index, upload) {
            if (result.errorCode === "0") {
                layer.msg("操作成功！");
                loadingPage("/admin/floorplan/floorplan");
            }
        }
        , error: function (index, upload) {
            // layer.msg("上传失败");
        }
    });
}